home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 4 / Info_Mac IV CD-ROM (Pacific HiTech Inc.)(August 1994).iso / Development / Source / MSG Demo 1.4.source Folder / Demo ƒ / Shell ƒ / about MSG.c next >
Text File  |  1994-04-15  |  7KB  |  253 lines

  1. /**********************************************************************\
  2.  
  3. File:        about MSG.c
  4.  
  5. Purpose:    This module handles displaying the "About MSG" splash
  6.             screen.
  7.  
  8. This program is free software; you can redistribute it and/or modify
  9. it under the terms of the GNU General Public License as published by
  10. the Free Software Foundation; either version 2 of the License, or
  11. (at your option) any later version.
  12.  
  13. This program is distributed in the hope that it will be useful,
  14. but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16. GNU General Public License for more details.
  17.  
  18. You should have received a copy of the GNU General Public License
  19. along with this program in a file named "GNU General Public License".
  20. If not, write to the Free Software Foundation, 675 Mass Ave,
  21. Cambridge, MA 02139, USA.
  22.  
  23. \**********************************************************************/
  24.  
  25. #include "graphics.h"        /* needs to come first because it defines WindowDataHandle */
  26. #include "about MSG.h"
  27. #include "environment.h"
  28. #include "sounds.h"
  29.  
  30. extern Point RawMouse : 0x82C;
  31.  
  32. /*-----------------------------------------------------------------------------------*/
  33. /* internal stuff for about MSG.c                                                    */
  34.  
  35. void SetupTheAboutMSGWindow(WindowDataHandle theData);
  36. void OpenTheMSGWindow(WindowDataHandle theData);
  37. void DrawTheAboutMSGWindow(void);
  38. void DoTheMSGThing(WindowDataHandle theData);
  39. void ActivateTheMSGWindow(void);
  40. void DeactivateTheMSGWindow(WindowDataHandle theData);
  41. void GetTheNextLine(Handle textHandle, unsigned long theSize, unsigned long *pos, Str255 theLine);
  42. void DrawTheAboutString(Str255 theString, int theWidth, int *theRow);
  43. void DrawTheCarpet(void);
  44. void DrawTheString(Str255 theString, int theWidth, int* theRow);
  45. void DrawCarpet(int x, int y, int len);
  46.  
  47. static int        gOldForegroundTime;
  48.  
  49. int AboutMSGBoxDispatch(ExtendedWindowDataHandle theData, int theMessage, unsigned long misc)
  50. {
  51.     int                theDepth;
  52.     
  53.     switch (theMessage)    /* see graphics.h for list of messages*/
  54.     {
  55.         case kNull:
  56.             if (!gIsInBackground)
  57.                 DoTheMSGThing(theData);
  58.             return kSuccess;
  59.             break;
  60.         case kUpdate:
  61.             DrawTheAboutMSGWindow();
  62.             return kSuccess;
  63.             break;
  64.         case kOpen:
  65.             OpenTheMSGWindow(theData);
  66.             return kSuccess;
  67.         case kActivate:
  68.             ActivateTheMSGWindow();
  69.             return kSuccess;
  70.             break;
  71.         case kDeactivate:
  72.             DeactivateTheMSGWindow(theData);
  73.             return kSuccess;
  74.             break;
  75.         case kKeydown:                            /* close about box on keypress */
  76.         case kMousedown:                        /* or mouseclick */
  77.             CloseTheWindow(theData);
  78.             return kSuccess;
  79.             break;
  80.         case kStartup:
  81.             SetupTheAboutMSGWindow(theData);
  82.             return kSuccess;
  83.             break;
  84.     }
  85.     
  86.     return kFailure;        /* for all other messages, defer to default processing */
  87. }
  88.  
  89. void SetupTheAboutMSGWindow(WindowDataHandle theData)
  90. {
  91.     (**theData).windowWidth=243;
  92.     (**theData).windowHeight=243;
  93.     (**theData).windowType=plainDBox;        /* plain rectangle */
  94.     (**theData).windowTitle[0]=0x00;        /* null title, never shown */
  95.     (**theData).hasCloseBox=FALSE;
  96. }
  97.  
  98. void OpenTheMSGWindow(WindowDataHandle theData)
  99. {
  100.     unsigned long    dummy;
  101.     
  102.     DoSound(sound_aboutMSG, TRUE);
  103.     UpdateTheWindow(theData);
  104.     Delay(30, &dummy);
  105. }
  106.  
  107. void ActivateTheMSGWindow(void)
  108. {
  109.     gOldForegroundTime=gForegroundWaitTime;
  110.     gForegroundWaitTime=0;
  111. }
  112.  
  113. void DeactivateTheMSGWindow(WindowDataHandle theData)
  114. {
  115.     UpdateTheWindow(theData);
  116.     gForegroundWaitTime=gOldForegroundTime;
  117. }
  118.  
  119. void DoTheMSGThing(WindowDataHandle theData)
  120. {
  121.     Rect            sourceRect, destRect;
  122.     Rect            mainRect;
  123.     long            lr,tb;
  124.     int                l,t;
  125.     int                index;
  126.     
  127.     index=(**theData).windowIndex;
  128.     mainRect=screenBits.bounds;
  129.     if (PtInRect(RawMouse, &mainRect))
  130.     {
  131.         lr=RawMouse.h-mainRect.left;
  132.         lr*=81;
  133.         lr/=mainRect.right-mainRect.left;
  134.         tb=RawMouse.v-mainRect.top;
  135.         tb*=81;
  136.         tb/=mainRect.bottom-mainRect.top;
  137.         if (tb<0)
  138.             tb=0;
  139.         l=RawMouse.h-lr;
  140.         t=RawMouse.v-tb;
  141.         SetRect(&sourceRect, l, t, l+81, t+81);
  142.         SetRect(&destRect, 81, 81, 162, 162);
  143.         SetPort(gTheWindow[index]);
  144.         CopyBits(&(WMgrPort->portBits), &(gTheWindow[index]->portBits),
  145.             &sourceRect, &destRect, 0, 0L);
  146.     }
  147. }
  148.  
  149. void DrawTheAboutMSGWindow(void)
  150. {
  151.     int                row;
  152.     Rect            sourceRect, destRect;
  153.     GrafPtr            curPort;
  154.     int                theWidth;
  155.     
  156.     GetPort(&curPort);
  157.     EraseRect(&(curPort->portRect));
  158.     theWidth=curPort->portRect.right-curPort->portRect.left;
  159.     
  160.     DrawCarpet(9,234,3);
  161.     SetRect(&sourceRect, 0, 216, 27, 243);
  162.     destRect=sourceRect;
  163.     OffsetRect(&destRect, 27, 0);
  164.     CopyBits(&(curPort->portBits), &(curPort->portBits),
  165.         &sourceRect, &destRect, 0, 0L);
  166.     OffsetRect(&destRect, -27, -27);
  167.     CopyBits(&(curPort->portBits), &(curPort->portBits),
  168.         &sourceRect, &destRect, 0, 0L);
  169.     OffsetRect(&destRect, 0, -27);
  170.     CopyBits(&(curPort->portBits), &(curPort->portBits),
  171.         &sourceRect, &destRect, 0, 0L);
  172.     OffsetRect(&destRect, 27, 0);
  173.     CopyBits(&(curPort->portBits), &(curPort->portBits),
  174.         &sourceRect, &destRect, 0, 0L);
  175.     SetRect(&sourceRect, 0, 162, 27, 243);
  176.     destRect=sourceRect;
  177.     OffsetRect(&destRect, 54, 0);
  178.     CopyBits(&(curPort->portBits), &(curPort->portBits),
  179.         &sourceRect, &destRect, 0, 0L);
  180.     SetRect(&sourceRect, 0, 162, 81, 243);
  181.     destRect=sourceRect;
  182.     OffsetRect(&destRect, 81, 0);
  183.     CopyBits(&(curPort->portBits), &(curPort->portBits),
  184.         &sourceRect, &destRect, 0, 0L);
  185.     OffsetRect(&destRect, -81, -81);
  186.     CopyBits(&(curPort->portBits), &(curPort->portBits),
  187.         &sourceRect, &destRect, 0, 0L);
  188.     OffsetRect(&destRect, 0, -81);
  189.     CopyBits(&(curPort->portBits), &(curPort->portBits),
  190.         &sourceRect, &destRect, 0, 0L);
  191.     OffsetRect(&destRect, 81, 0);
  192.     CopyBits(&(curPort->portBits), &(curPort->portBits),
  193.         &sourceRect, &destRect, 0, 0L);
  194.     SetRect(&sourceRect, 0, 0, 81, 243);
  195.     destRect=sourceRect;
  196.     OffsetRect(&destRect, 162, 0);
  197.     CopyBits(&(curPort->portBits), &(curPort->portBits),
  198.         &sourceRect, &destRect, 0, 0L);
  199.     
  200.     TextFont(geneva);
  201.     TextSize(9);
  202.     TextMode(srcXor);
  203.     row=92;
  204.     DrawTheString("\pMerriMac", theWidth, &row);
  205.     DrawTheString("\pSoftware", theWidth, &row);
  206.     DrawTheString("\pGroup ’94", theWidth, &row);
  207.     DrawTheString("\p", theWidth, &row);
  208.     DrawTheString("\pStill enhancing", theWidth, &row);
  209.     DrawTheString("\pthe flavor of", theWidth, &row);
  210.     DrawTheString("\pyour Macintosh.", theWidth, &row);
  211. }
  212.  
  213. void DrawTheString(Str255 theString, int theWidth, int* theRow)
  214. {
  215.     MoveTo((theWidth-StringWidth(theString))/2, *theRow);
  216.     DrawString(theString);
  217.     *theRow+=11;
  218. }
  219.  
  220. void DrawCarpet(int x, int y, int len)
  221. {
  222.     Rect            box;
  223.     int                iter;
  224.  
  225.     x-=len*2;
  226.     y+=len*2;
  227.     for (iter=0; iter<8; iter++)
  228.     {
  229.         box.left=x-len;
  230.         box.right=x+2*len;
  231.         box.top=y-2*len;
  232.         box.bottom=y+len;
  233.         FillRect(&box, black);
  234.         if (len>1) DrawCarpet(x,y,len/3);
  235.         box.left=x;
  236.         box.right=x+len;
  237.         box.bottom=y;
  238.         box.top=y-len;
  239.         FillRect(&box, white);
  240.         switch (iter)
  241.         {
  242.             case 0:
  243.             case 1: x+=len*3; break;
  244.             case 2:
  245.             case 3: y-=len*3; break;
  246.             case 4:
  247.             case 5: x-=len*3; break;
  248.             case 6:
  249.             case 7: y+=len*3; break;
  250.         }
  251.     }
  252. }
  253.